//package com.wulaobo.test;
//
//import org.apache.flink.streaming.api.datastream.DataStreamSource;
//import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
//import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction;
//
//import java.util.Random;
//
//public class ParallelSourceExample {
//
//    public static void main(String[] args) throws Exception {
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(4);
//
//        DataStreamSource<Integer> streamSource = env.addSource(new CustomSource()).setParallelism(2);
//        streamSource.print();
//        env.execute();
//
//    }
//
//    public static class CustomSource implements ParallelSourceFunction<Integer>{
//
//        private boolean running = true;
//        private Random random = new Random();
//
//        @Override
//        public void run(SourceContext<Integer> sourceContext) throws Exception {
//            while (running) {
//                sourceContext.collect(random.nextInt());
//                Thread.sleep(1000);
//            }
//        }
//
//        @Override
//        public void cancel() {
//            running = false;
//        }
//    }
//
//}
